<?php
/*
 * @Author: 哲学家乔布斯 <wuyangii@qq.com>
 * @Date: 2022-10-20 21:41:37
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2022-11-07 22:37:15
 * @Descripttion: 我的
 */

namespace app\api\controller\user\v1_0;



class User extends Common
{
    protected $noNeedRight = ['index'];
    /**
     * @Author: 哲学家乔布斯 <wuyangii@qq.com>
     * @brief: 
     * @return 
     * @Descripttion: 首页默认接口
     */    
    public function index(){
        $user = (new \app\common\model\User())
                    ->field(['id','nickname','avatar','money'])
                    ->where(['id' => $this->UserInfo['id']])
                    ->find();
        $bus = (new \app\common\model\Bus())->where(['user_id' => $this->UserInfo['id']])->find();
        return self::successResult("成功",[
            'user' => $user,
            'is_bus' => !empty($bus) ? 1 : 0,
            'order' => [
                'order_count_0' => (new \app\common\model\UserOrders())->where(['user_id' => $this->UserInfo['id'],'state' => 0])->count(),
                'order_count_1' => (new \app\common\model\UserOrders())->where(['user_id' => $this->UserInfo['id'],'state' => 1])->count(),
                'order_count_2' => (new \app\common\model\UserOrders())->where(['user_id' => $this->UserInfo['id'],'state' => 2])->count(),
                'order_count_3' => (new \app\common\model\UserOrders())->where(['user_id' => $this->UserInfo['id'],'state' => 3])->count(),
                'order_count_4' => (new \app\common\model\UserOrders())->where(['user_id' => $this->UserInfo['id'],'state' => 4])->count(),
                'order_count_5' => (new \app\common\model\UserOrders())->where(['user_id' => $this->UserInfo['id'],'state' => 5])->count(),
            ]
        ]);
    }

    public function edit(){
        $param = request()->param();
        $data=[];
        if(!empty($param['avatar'])){
            $data['avatar'] = $param['avatar'];
        }
        if(!empty($param['nickname'])){
            $data['nickname'] = $param['nickname'];
        }
        (new \app\common\model\User())->where(['id' => $this->UserInfo['id']])->update($data);
        return self::successResult("成功");
    }
    

}
